package com.software.seakdream.controller;

import com.software.seakdream.domain.Result;
import com.software.seakdream.entity.ClockInfo;
import com.software.seakdream.entity.SleepInfo;
import com.software.seakdream.entity.UserInfo;
import com.software.seakdream.service.ClockInfoService;
import com.software.seakdream.service.SleepInfoService;
import com.software.seakdream.utils.ResultUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/sleep")
public class SleepInfoController {

    @Autowired
    private SleepInfoService sleepInfoService;


    @GetMapping("/findSleepInfoById")
    public Result findClockInfoById(String sleepId) {
        SleepInfo sleepInfo = sleepInfoService.findSleepInfoById(sleepId);
        return ResultUtils.success(sleepInfo);
    }
    @GetMapping("/findLastSleepInfo")
    public Result findLastSleepInfo(String userId){
        SleepInfo sleepInfo = sleepInfoService.findLastSleepInfo(userId);
        return ResultUtils.success(sleepInfo);
    }

    @PostMapping("/createSleepInfo")
    public Result createSleepInfo(SleepInfo sleepInfo) {
        int i = sleepInfoService.createSleepInfo(sleepInfo);
        return ResultUtils.success(i);
    }

    @GetMapping("/findSleepInfoUsePage")
    public Result findSleepInfoUsePage(String userId,int page){
        int pageSize = 20;
        List<SleepInfo> sleepInfos = sleepInfoService.findSleepInfoUsePage(userId,page,pageSize);
        return ResultUtils.success(sleepInfos);
    }
    @GetMapping("/findSleepInfoInRange")
    public Result findSleepInfoInRange(String userId,String left,String right){
        List<SleepInfo> sleepInfos = sleepInfoService.findSleepInfoInRange(userId,left,right);
        return ResultUtils.success(sleepInfos);
    }

}
